package com.lxl.dao.impl;

import com.lxl.dao.IDao;
import com.lxl.entity.User;
import com.lxl.mapper.IMapper;
import com.lxl.mapper.impl.UserMapperImpl;
import com.lxl.utils.DbUtil;


import javax.servlet.jsp.jstl.sql.Result;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @author 北上寻海
 */

public class UserDaoImpl implements IDao {

    @Override
    public int addUser(User user) throws SQLException {
        int result = -1;
        String userName =user.getUserName();
        String password = user.getPassword();
        String sql = "insert into user(id,user_name,password) values(null,'"+userName+"','"+password+"') ";
       return DbUtil.update(sql);
    }

    @Override
    public Result findById(Object[] params) throws SQLException {
        String sql = "select id,user_name,password from user where id=? or id=? or id = ?";
          return DbUtil.select(sql,params);

    }



    @Override
    public Result findAll() throws SQLException {
        String sql = "select id,user_name,password from user";
       return DbUtil.select(sql);

    }

    @Override
    public int deleteUserById(int id) throws SQLException {
         String sql = "delete from user where id = ?";
         return DbUtil.update(sql,id);
    }

    @Override
    public int updateUserById(Object[] params) throws SQLException {
         String sql = "update user set user_name = ?,password = ? where id=?";
         return DbUtil.update(sql,params);
    }

    @Override
    public Result verify(String username,String password) throws SQLException {
        String sql = "select id,user_name,password from user where user_name= ? and password = ?";
         return   DbUtil.select(sql,username,password);

    }
}
